<?php
/**
 * Created by: i@fedax.cn
 * Date: 2018/7/29 0:16
 */

namespace app\admin\model;


class FamilyMembers extends DataBase
{
    protected $name = 'family_members';
    protected $autoWriteTimestamp = true;

    /**
     * @return array
     * @title 家庭成员信息
     * @author shuaishuai wu
     * @date 2018/11/7
     * @time 15:26
     */
    public function familyMemberInfoData()
    {
        $family_id = input('family_id');
        $user_id = input('user_id');
        $page_config = array(
            'offset' => input('get.offset',1),
            'limit' => input('get.limit',10)
        );
        $result = $this
            ->where(['family_id'=>$family_id])
            ->paginate($page_config);
        $data = [];
        foreach($result as $key => $value){
            $userData = User::where('id='.$value['user_id'])->find();
            $arr['u_id'] = $userData['u_id'];
            $arr['nickname'] = $userData['nickname'];
            $arr['phone'] = $userData['u_phone'];
            $arr['followers'] = Follower::where('follow_user_id', $value['user_id'])->count();
            $arr['friends'] = Follower::where('user_id', $value['user_id'])->count();
            $is_head = $value['user_id'] == $user_id ?'是':'否';  //是否族长
            $arr['is_head'] = $is_head;
            $data[] = $arr;
        }
        return ['resultCode'=>100, 'resultData'=>$data,'resultDes' =>'查询成功'];
    }
    public function familyMemberDetail()
    {
        $u_id = input('u_id');
        $page_config = array(
            'offset' => input('get.offset',1),
            'limit' => input('get.limit',10)
        );
        $result = $this
            ->where(['family_id'=>$u_id])
            ->paginate($page_config);
        $data = [];
        foreach($result as $key => $value){
            $userData = User::where('id='.$value['user_id'])->find();
            $arr['u_id'] = $userData['u_id'];
            $arr['nickname'] = $userData['nickname'];
            $arr['phone'] = $userData['u_phone'];
            $data[] = $arr;
        }
        return ['resultCode'=>100, 'resultData'=>$data,'resultDes' =>'查询成功'];
    }
}